﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Shop_HelpType_Info : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadType();
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页        

        base.OnLoad(e);
    }

    #endregion

    private void LoadType()
    {
        DataTable dt = new DAL.Tables.tbl_Site_HelpType().Open("", "ParentID != 0", "");

        ddlType.DataSource = dt;
        ddlType.DataTextField = "TypeName";
        ddlType.DataValueField = "ID";
        ddlType.DataBind();
    }

    private void BindData()
    {
        int TypeID = Shove._Convert.StrToInt(ddlType.SelectedValue, 0);

        DataTable dt = new DAL.Tables.tbl_Site_HelpExpress().Open("","TypeID=" + TypeID,"");

        if (dt != null && dt.Rows.Count > 0)
        {
            string Content = Shove._String.Decompress((byte[])dt.Rows[0]["ValueBinary"]);

            tbContent.Value = Content;
        }
        else
        {
            tbContent.Value = "";
        }
    }

    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindData();
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        DAL.Tables.tbl_Site_HelpExpress table = new DAL.Tables.tbl_Site_HelpExpress();
        table.ValueBinary.Value = Shove._String.Compress(tbContent.Value);
        table.TypeID.Value = ddlType.SelectedValue;       
        
        //该类别是否已经存在,存在则修改
        int TypeID = Shove._Convert.StrToInt(ddlType.SelectedValue, 0);
        DataTable dt = new DAL.Tables.tbl_Site_HelpExpress().Open("","TypeID=" + TypeID,"");
        long i = 0;

        if (dt != null && dt.Rows.Count > 0)
        {
            i = table.Update("TypeID=" + TypeID);
        }
        else
        {
            i = table.Insert();
        }

        if (i >= 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "保存成功。");
        }
    }

}
